package com.zhuzhe.blog.article.controller;


import com.zhuzhe.blog.article.requestDto.CommentDto;
import com.zhuzhe.blog.article.service.ICommentService;
import com.zhuzhe.blog.base.JsonData;
import com.zhuzhe.blog.base.ResponseData;
import com.zhuzhe.blog.article.entity.Comment;
import com.zhuzhe.blog.convert.Convert;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评论信息表 前端控制器
 * </p>
 *
 * @author u53
 * @since 2020-10-07
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    @ApiImplicitParam(name = "id", value = "评论ID", required = true)
    @ApiOperation("删除评论接口")
    @DeleteMapping("/{id}")
    public ResponseData delete(@PathVariable("id") String id) {
        return commentService.deleteById(id);
    }

    @ApiOperation("新增评论信息接口")
    @PostMapping
    public ResponseData<String> save(@RequestBody CommentDto commentDto) {
        Comment comment = new Comment();
        Convert.convertType(commentDto,comment);
        commentService.save(comment);
        return JsonData.success(comment.getId());
    }

}
